package com.dyxy.tms;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class UserInfo {
	private static JSONObject data;
	private String username, password;
	private static List<Map<String, Object>> listIcon,listLv,listLb ;
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public static void getJsonArray(String string) {
		try {
			data = new JSONObject(string);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static List<Map<String, Object>> getIndexLBList(String string) {
		
		if (data == null) {
			getJsonArray(string);
			
		}
		listLb = new ArrayList<Map<String, Object>>();
		try {
			JSONArray jsonArray = data.getJSONArray("lbs");
			for (int i = 0; i < jsonArray.length(); i++) {
				Map<String, Object> map = new HashMap<String, Object>();
				JSONObject jb = jsonArray.getJSONObject(i);
				String img = jb.getString("img");
				map.put("img", img);
				listLb.add(map);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return listLb;
	}

	public static List<Map<String, Object>> getIndexIconList(String string) {
		if (data == null) {
			getJsonArray(string);
		}
		listIcon = new ArrayList<Map<String, Object>>();
		try {
			JSONArray jsonArray = data.getJSONArray("cate");
			for (int i = 0; i < jsonArray.length(); i++) {
				Map<String, Object> map = new HashMap<String, Object>();
				JSONObject jb = jsonArray.getJSONObject(i);
				String title = jb.getString("title");
				String img = jb.getString("img");
				map.put("img", img);
				map.put("title", title);
//				String type = jsonObject.optString("type").toString();
//				map.put("type", type);
				listIcon.add(map);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}

		return listIcon;
	}

	public static List<Map<String, Object>> getIndexCourseList(String string) {
		if (data == null) {
			getJsonArray(string);
		}
		listLv = new ArrayList<Map<String, Object>>();
		try {
			JSONArray jsonArray = data.getJSONArray("crouse");
			Map<String, Object> map = new HashMap<String, Object>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				String name = jsonObject.opt("name").toString();
				map.put("name", name);
				String adress = jsonObject.opt("adress").toString();
				map.put("adress", adress);
//				String time = jsonObject.opt("time").toString();
//				map.put("time", time);
				String teacher = jsonObject.opt("teacher").toString();
				map.put("teacher", teacher);
				listLv.add(map);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return listLv;
	}

}
